﻿package mortal.game.view.copy.GroupTowerCopy.panel
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GroupTowerPassWin extends BaseWindow
    {
        protected var _bg:ScaleBitmap;
        protected var _code:GTextFiled;
        protected var _level:GTextFiled;
        protected var _nextBtn:GButton;
        private var _secTimer:SecTimer;
        private var _timeOutNum:int = 10;
        private var _info:SGroupTowerPassMsg;
        private static var _instance:GroupTowerPassWin;

        public function GroupTowerPassWin(param1:ILayer = null)
        {
            super(param1);
            setSize(320, 190);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(8, 37, 303, 143, this, ImagesConst.PanelBg);
            this._code = UIFactory.gTextField("" + Language.getString(70923), 50, 65, 200, 20, this, GlobalStyle.textFormatPutong.center());
            this._level = UIFactory.gTextField("" + Language.getString(70924), 94, 94, 100, 20, this, GlobalStyle.textFormatPutong.center());
            this._nextBtn = UIFactory.gButton("" + Language.getString(70925), 108, 127, 77, 30, this);
            this._secTimer = new SecTimer(1);
            this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            this._secTimer.repeatCount = this._timeOutNum;
            this._nextBtn.configEventListener(MouseEvent.CLICK, this.onEnterNext);
            _closeBtn.visible = false;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._code = null;
            this._level = null;
            this._nextBtn = null;
            this._secTimer.stop();
            this._secTimer = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onTimerCompleteHandler(param1:SecTimer) : void
        {
            this.onEnterNext(null);
            return;
        }// end function

        private function onEnterFrameHandler(param1:SecTimer) : void
        {
            this._nextBtn.label = Language.getStringByParam(70926, param1.repeatCount);
            return;
        }// end function

        public function updatePassInfo(param1:SGroupTowerPassMsg) : void
        {
            this._info = param1;
            var _loc_2:* = GroupTowerConfig.instance.getInfoByCodeAndLvl(this._info.copyCode, this._info.level);
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = parseInt(_loc_2.passCondition);
            var _loc_4:* = BossConfig.instance.getInfoByCode(_loc_3);
            this._code.htmlText = Language.getString(70927) + HTMLUtil.addColor(_loc_4.name, "#00ff00");
            this._level.htmlText = Language.getStringByParam(70928, HTMLUtil.addColor("" + param1.level, "#00ff00"));
            this._nextBtn.label = Language.getStringByParam(70926, this._timeOutNum);
            this._secTimer.start();
            return;
        }// end function

        private function onEnterNext(event:MouseEvent) : void
        {
            this._secTimer.stop();
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupTowerEnterNextLevel, this._info));
            this.hide();
            return;
        }// end function

        public static function get instance() : GroupTowerPassWin
        {
            if (_instance == null)
            {
                _instance = new GroupTowerPassWin;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
